<template>
  <view class="content">
    <button @click="registerAdmin">注册管理员</button>
    <button @click="createCaptcha">获取验证码</button>
    <input style="height: 90rpx" type="text" v-model="captcha" placeholder="输入验证码" />
    <button @click="login">登录</button>
    <!-- <button @click="check">检查登录状态</button> -->
    <button @click="logout">登出</button>
    <button @click="getToken">用户</button>
    <button @click="getMenuTree">getMenuTree</button>

    <hr />
    <image
      style="border: 1px solid red; height: 250rpx"
      :src="imageUrl"
      mode="aspectFill"
    ></image>

    <view>hello world</view>
  </view>
</template>

<script>
const uniIdCo = uniCloud.importObject('uni-id-co')
const User = uniCloud.importObject('user')
const Menu = uniCloud.importObject('menu')
export default {
  data() {
    return {
      imageUrl: '',
      captcha: ''
    }
  },
  onShow() {
    let res = uni.getSystemInfoAsync()
    console.log(res)
  },
  methods: {
    async registerAdmin() {
      let res = await uniIdCo.registerAdmin({
        username: 'admin',
        password: 'mo123456...',
        nickname: 'admin'
      })
      console.log(res)
    },
    async login() {
      let res = await uniIdCo.login({
        username: 'admin',
        password: 'mo123456...',
        captcha: this.captcha
      })

      console.log('登录结果====》')
      console.log(res)
    },
    async check() {},
    async logout() {
      await uniIdCo.logout()
    },
    async createCaptcha() {
      let res = await uniIdCo.createCaptcha({
        // scene: 'login-by-pwd'
        scene: 'register'
      })
      console.log(res)
      this.imageUrl = res.captchaBase64
    },

    async getToken() {
      let res = await User.getUsers()
      console.log(res)
    },

    async getMenuTree() {
      let res = await Menu.getMenuTree()
      console.log(res)
    }
  }
}
</script>

<style>
.content {
  padding: 30rpx;
}
</style>
